<template>
	<view class="home">
		<view class="tab-box">
			<text :class="current == 0?'active':''" @click="changeCurrent(0)">待审核</text>
			<text :class="current == 1?'active':''" @click="changeCurrent(1)">未通过</text>
			<text :class="current == 2?'active':''" @click="changeCurrent(2)">采购中</text>
			<text :class="current == 3?'active':''" @click="changeCurrent(3)">已完成</text>
			<view class="bar" :style="{left:leftBar+'rpx'}"></view>
		</view>
		<view class="goods-item" v-for="(item,index) in list" :key="item.id">
			<view class="goods">
				<image :src="item.thumb_image_text" class="goods-img" mode=""></image>
				<view class="goods-content">
					<view class="goods-name">{{item.name}}</view>
					<view class="goods-time">{{$wanlshop.timeFormat(item.createtime)}}</view>
				</view>
				<image src="/static/images/user/icon_dsh.png" v-if="current == 0" class="goods-status" mode=""></image>
				<image src="/static/images/user/icon_wtg.png" v-if="current == 1" class="goods-status" mode=""></image>
				<image src="/static/images/user/icon_cgz.png" v-if="current == 2" class="goods-status" mode=""></image>
				<image src="/static/images/user/icon_ywc.png" v-if="current == 3" class="goods-status" mode=""></image>
			</view>
			<view class="goods-action" v-if="current == 0 || current == 2">
				<view class="action-item" @click="changeStatus(item,0)">
					<image src="/static/images/user/icon_qx.png"></image>
					<text>取消</text>
				</view>
				<view class="action-item" v-if="current == 0" @click="handleDetail(item)">
					<image src="/static/images/user/icon_bj.png"></image>
					<text>编辑</text>
				</view>
				<view class="action-item" v-if="current == 2" @click="changeStatus(item,2)">
					<image src="/static/images/user/icon_wc.png"></image>
					<text>完成</text>
				</view>
			</view>
		</view>
		<image src="/static/images/user/icon_add.png" @click="handleDetail()" class="icon-add" mode=""></image>
		<image src="/static/images/user/icon_empty.png" v-if="!list.length" class="icon-empty" mode=""></image>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				current: 0,
				params: {
					state: 0,
					page: 1,
					pageSize: 20,
				},
				list: []
			};
		},
		computed: {
			leftBar() {
				switch (this.current) {
					case 0:
						return 46
					case 1:
						return 248
					case 2:
						return 450
					case 3:
						return 664
				}
				return
			}
		},
		onReachBottom() {
			this.params.page++
			this.mylists()
		},
		onLoad(option) {
			if (option.state) {
				this.current = +option.state
			}
		},
		onShow() {
			this.mylists()
		},
		methods: {
			changeStatus(item, status) {
				uni.showModal({
					content: '确定要执行该操作吗？',
					success: (result) => {
						if (result.confirm) {
							uni.request({
								url: `/xilumarket.recovery/multiStatus`,
								method: 'POST',
								data: { product_id: item.id, status },
								success: ({ res }) => {
									this.mylists()
								}
							})
						}
					}
				})
			},
			changeCurrent(current) {
				this.current = current
				this.params.state = this.current
				this.params.page = 1
				this.list = []
				this.mylists()
			},
			// 编辑
			handleDetail(item = {}) {
				uni.navigateTo({
					url: `/pages/user/goodsManage/sendGoods?id=${item.id||''}`
				})
			},
			// 获取列表
			mylists() {
				uni.request({
					url: '/xilumarket.recovery/mylists',
					method: 'GET',
					data: this.params,
					success: ({
						data
					}) => {
						let res = data
						console.log(res)
						if (this.params.page == 1) {
							this.list = res.data
						} else {
							this.list = [...this.list, ...res.data]
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tab-box {
		display: flex;
		align-items: center;
		padding: 24rpx;
		justify-content: space-between;
		background: #fff;
		top: 0;
		z-index: 9;
		font-size: 28rpx;
		color: #999;
		position: relative;
		transition: all .3s;

		.active {
			color: #ef5d0f;
			font-weight: 800;
		}

		.bar {
			position: absolute;
			bottom: 0;
			left: 68rpx;
			width: 48rpx;
			height: 4rpx;
			transition: all .3s;
			background: #EF5D0F;
		}
	}

	.goods-item {
		width: 696rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		margin: 20rpx auto;

		.goods {
			padding: 30rpx 26rpx;
			border-bottom: 1px solid #f5f5f5;
			font-size: 28rpx;
			color: #333;
			font-weight: 500;
			position: relative;

			.goods-img {
				width: 160rpx;
				height: 160rpx;
			}

			.goods-name {
				display: -webkit-box;
				-webkit-line-clamp: 2;
				/* 设置你想显示的最大行数 */
				-webkit-box-orient: vertical;
				overflow: hidden;
				text-overflow: ellipsis;
				width: 100%;
			}

			.goods-status {
				width: 80rpx;
				height: 80rpx;
				position: absolute;
				right: 26rpx;
			}

			.goods-content {
				height: 160rpx;
				display: inline-flex;
				vertical-align: top;
				margin-left: 20rpx;
				flex-direction: column;
				justify-content: space-between;
				width: calc(100% - 300rpx);
			}

			.goods-time {
				font-weight: 500;
				font-size: 24rpx;
				color: #999999;
			}
		}

		.goods-action {
			padding: 30rpx 64rpx 30rpx 90rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.action-item {
				color: #333;
				font-size: 28rpx;

				text {
					margin-left: 10rpx;
					vertical-align: top;
				}

				image {
					width: 40rpx;
					height: 40rpx;
				}
			}
		}
	}

	.icon-add {
		position: fixed;
		right: 32rpx;
		bottom: 200rpx;
		width: 100rpx;
		height: 100rpx;
	}

	.icon-empty {
		width: 424rpx;
		height: 424rpx;
		position: absolute;
		left: 0;
		right: 0;
		top: 262rpx;
		margin: auto;
	}
</style>